/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

// partition manager

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __PONY_HAL_PART_H__
#define __PONY_HAL_PART_H__

/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_common.h>
/* includes (local) ----------------------------------------------------------*/
#include <hal_mtd.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/

typedef struct hal_logic_part {
    uint32_t part_id;
    uint32_t dev_id;
    const char *name;
    size_t start_addr;
    size_t size;
} hal_logic_part_t;

typedef struct hal_physic_dev {
    uint32_t dev_id;
    const char *name;
    hal_mtd_t *mtd;
} hal_physic_dev_t;

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern int hal_part_erase(uint32_t part_id, size_t offset, size_t len);
extern int hal_part_read(uint32_t part_id, size_t offset, size_t len, void *buf);
extern int hal_part_write(uint32_t part_id, size_t offset, size_t len, const void *buf);
extern int hal_part_write_safe(uint32_t part_id, size_t offset, size_t len, const void *buf);
extern int hal_part_erase_write(uint32_t part_id, size_t offset, size_t len, const void *buf);
extern int hal_part_get_start_addr(uint32_t part_id, size_t *addr);
extern int hal_part_get_size(uint32_t part_id, size_t *size);
extern int hal_part_register(hal_logic_part_t part[], uint32_t part_cnt, hal_physic_dev_t dev[],
                             uint32_t dev_cnt);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __PONY_HAL_PART_H__ */
